<template>
  <div class="shelf-wrapper">
    <ShelfUserInfo
      :num="num"
      :readDay="readDay"
      :userInfo="userInfo"
    ></ShelfUserInfo>
    <ShelfList :shelfList="shelfList"></ShelfList>
  </div>
</template>

<script>
import ShelfUserInfo from '../../components/shelf/shelfUserInfo'
import ShelfList from '../../components/shelf/shelfList'
import { getStorageSync } from '../../api/wechat'
import { getShelfList, getUserDay } from '../../api/index'
export default {
  components: { ShelfUserInfo, ShelfList },
  data () {
    return {
      shelfList: [],
      // 书架图书数量
      num: 0,
      readDay: 0,
      userInfo: {}
    }
  },
  mounted () {
    this.getUserInfo()
    this.getUserDay()
  },
  onShow () {
    this.getShelfList()
  },
  methods: {
    async getShelfList () {
      const { data: { data } } = await getShelfList()
      this.num = data.length
      // push一个空对象，是为了加最后一个添加图书的框框
      data.push({})
      this.shelfList = data
    },
    getUserInfo () {
      this.userInfo = getStorageSync('userInfo')
    },
    async getUserDay () {
      const { data: { data } } = await getUserDay()
      this.readDay = data.day
    }
  }
}
</script>

<style lang="scss" scoped>
</style>